package com.test.service.impl;

import com.test.dao.IBuildValveCurrentDao;
import com.test.model.BuildValveCurrentData;
import com.test.service.IBuildValueCurrentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * Created by ZZF on 2017/7/5.
 */
@Service
public class BuildValveCurrentServiceImpl implements IBuildValueCurrentService {

    @Autowired
    IBuildValveCurrentDao buildValveCurrentDao;

    @Override
    public void updateOpen() {
        List<BuildValveCurrentData> all = buildValveCurrentDao.getAll(BuildValveCurrentData.class);
        if(!all.isEmpty()){
            for (BuildValveCurrentData buildValveCurrentData : all) {
                //给开度一个随机值
                int random = (int) (Math.random() * 100);
                BigDecimal open = new BigDecimal(random);
                buildValveCurrentData.setActualOpening(open);
                buildValveCurrentData.setPlanTime(new Date());

                buildValveCurrentDao.update(buildValveCurrentData);
            }
        }

    }


}
